package com.atguigu.yygh.task.scheduled;

import com.atguigu.yygh.rabbit.enums.MqConst;
import com.atguigu.yygh.rabbit.service.RabbitService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @program: yygh_parent
 * @author: Mr.Zhuo
 * @create: 2022-03-20 21:13
 **/
@Component
@EnableScheduling
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;

    /**
     * 定时任务每天晚上八点进行发送消息
     */
    @Scheduled(cron = "0 0 20 * * ?")
    //@Scheduled(cron = "0/10 * * * * ?")
    public void tastDemo() {
        //获取查询的时间
        DateTime dateTime = new DateTime().plusDays(1);
        String dateString = dateTime.toString("yyyy-MM-dd");
        //发送mq消息发送短信
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,
                MqConst.ROUTING_TASK_8, dateString);
    }
}
